

#include "InetAddress.hpp"
#include "Socket.hpp"
#include "Channel.hpp"

#include <functional>
using namespace std;

#ifndef ACCEPTOR_HPP
#define ACCEPTOR_HPP

namespace tulun
{
    class EventLoop;
    class Acceptor
    {
    public:
        using NewConnectionCallback = std::function<void(int connfd, const InetAddress &)>;

    private:
        NewConnectionCallback newConnectionCallback_;

    public:
        void setNewConnectionCallback(const NewConnectionCallback &cb)
        {
            newConnectionCallback_ = cb;
        }

    private:
        tulun::Socket acceptSocket_;
        bool listenning_;
        EventLoop *loop_;
        tulun::Channel acceptChannel_;

        int idleFd_;
        void handleRead();

    public:
        Acceptor(EventLoop *loop, const InetAddress &, bool reuseport);
        ~Acceptor();
        bool listenning() const;
        void listen();
    };
} // namespace tulun

#endif